package com.novax.ex.activity.provider.handler.consumer;

import com.alibaba.fastjson.JSON;
import com.novax.ex.activity.infrastructure.entity.TaskAwardInfo;
import com.novax.ex.activity.provider.common.TaskCenter;
import com.novax.ex.activity.provider.service.TaskVersionInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;

@Slf4j
@Component
public class RegisterCustomer {

    @Resource
    private TaskVersionInfoService taskVersionInfoService;

    /**
     * 用户注册奖励方法的逻辑单独拿出来
     *
     * @param message 接收到用户注册的消息
     */
    @RabbitListener(queuesToDeclare = @Queue(value = TaskCenter.TASK_CENTER_AWARD, durable = "true"))
    public void userRegisterReward(String message) {
        try {
            log.info("mq consumer message:[{}]", message);
            TaskAwardInfo entity = JSON.parseObject(message, TaskAwardInfo.class);
            taskVersionInfoService.userRegisterReward(entity.getUserId());
        } catch (Exception e) {
            log.error("[注册完成消息消费异常] msg = {}", message, e);
        }
    }

}
